/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package clientFrame;

import views.CellRender;
import views.Status;
import ejb.sessions.TDSessionRemote;
import java.util.ArrayList;
import java.util.Date;
import javax.ejb.EJB;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import models.*;
import views.ComboBoxCellRender;

/**
 *
 * @author simone
 */
public class TDGuiMain extends javax.swing.JFrame {
    

    @EJB(name = "TDSession")
    private static TDSessionRemote tDSession;
    
    Status status;

    private final DefaultListModel listPacketModel;
    private ArrayList<PacchettoDTO> pack =null;
    private ArrayList<cittaDTO> cities =null;
    private PacchettoDTO selectedPacket;
    
    private static TDGuiMain guiMain;
    private static CreateFrame createFrame;
    private static ShowBookedFrame showBookFrame;
    private static BookingFrame bookFrame;
    private static LoginDialog dialog;
    private static HotelDialog hotelDialog;
    private static TourDialog tourDialog;
    private static TravelDialog travelDialog;

    private  UserDTO userLogged;
    
    public TDGuiMain() {
        initComponents();
        listPacketModel = new DefaultListModel();
        packetList.setModel(listPacketModel);
        packetList.setCellRenderer(new CellRender());
        fillCityBox();
        setCellRender();

    }
    
        
    private void setCellRender()
    {
        ComboBoxCellRender cellrender = new ComboBoxCellRender();
        cityArrBox.setRenderer(cellrender);
        cityDepBox.setRenderer(cellrender);  
    }
        
    private void fillCityBox()
    {
        this.cities = tDSession.getAllCity();
        cityArrBox.addItem("");
        cityDepBox.addItem("");
        for (cittaDTO c : cities) 
        {
            cityArrBox.addItem(c);
            cityDepBox.addItem(c);
        }
        
    }
    
    private void showPacketOnsale()
    {
        listPacketModel.clear();
        pack = tDSession.getAllPacketsOnsale();
        int size = pack.size();
        for (int i = 0; i < size; i++)  
            listPacketModel.addElement(pack.get(i));
    }
    
    private void showAllPackets()
    {
        listPacketModel.clear();
        pack = tDSession.getAllPackets();
        int size = pack.size();
        for (int i = 0; i < size; i++)  
            listPacketModel.addElement(pack.get(i));

    }
    /**
     * This method is called from within the constructor to initialize the form
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jMenu1 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        jScrollPane1 = new javax.swing.JScrollPane();
        packetList = new javax.swing.JList();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        DepartureDateField = new javax.swing.JFormattedTextField();
        arriveDateField = new javax.swing.JFormattedTextField();
        jSeparator1 = new javax.swing.JSeparator();
        searchBtn = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        userLabel = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        cityDepBox = new javax.swing.JComboBox();
        cityArrBox = new javax.swing.JComboBox();
        menuBar = new javax.swing.JMenuBar();
        infoMenu = new javax.swing.JMenu();
        prefItem = new javax.swing.JMenuItem();
        logoutItem = new javax.swing.JMenuItem();
        fileMenu = new javax.swing.JMenu();
        packetItem = new javax.swing.JMenuItem();
        bookingItem = new javax.swing.JMenuItem();
        editMenu = new javax.swing.JMenu();
        createPackItem = new javax.swing.JMenuItem();
        hotelMenu = new javax.swing.JMenuItem();
        tourMenu = new javax.swing.JMenuItem();
        travelMenu = new javax.swing.JMenuItem();

        jMenu1.setText("jMenu1");

        jMenuItem2.setText("jMenuItem2");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("TravelDream");
        addWindowFocusListener(new java.awt.event.WindowFocusListener() {
            public void windowGainedFocus(java.awt.event.WindowEvent evt) {
                formWindowGainedFocus(evt);
            }
            public void windowLostFocus(java.awt.event.WindowEvent evt) {
            }
        });

        packetList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        packetList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                packetListMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(packetList);

        jLabel1.setText("Citta partenza:");

        jLabel2.setText("Citta arrivo:");

        jLabel3.setText("Data partenza:");

        jLabel4.setText("Data ritorno:");

        DepartureDateField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd/MM/yyyy"))));

        arriveDateField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd/MM/yyyy"))));

        searchBtn.setText("Search");
        searchBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchBtnActionPerformed(evt);
            }
        });

        jLabel6.setText("Login as:");

        jLabel7.setText("Cerca:");

        infoMenu.setText("TravelDream");

        prefItem.setText("preferences");
        infoMenu.add(prefItem);

        logoutItem.setText("Logout");
        logoutItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                logoutItemActionPerformed(evt);
            }
        });
        infoMenu.add(logoutItem);

        menuBar.add(infoMenu);

        fileMenu.setText("File");

        packetItem.setText("Mostra pacchetti");
        packetItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemActionPerformed(evt);
            }
        });
        fileMenu.add(packetItem);

        bookingItem.setText("Mostra Prenotazioni");
        bookingItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bookingItemActionPerformed(evt);
            }
        });
        fileMenu.add(bookingItem);

        menuBar.add(fileMenu);

        editMenu.setText("Edit");

        createPackItem.setText("Crea pacchetto");
        createPackItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                createPackItemActionPerformed(evt);
            }
        });
        editMenu.add(createPackItem);

        hotelMenu.setText("Crea Hotel");
        hotelMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                hotelMenuActionPerformed(evt);
            }
        });
        editMenu.add(hotelMenu);

        tourMenu.setText("Crea Escursione");
        tourMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tourMenuActionPerformed(evt);
            }
        });
        editMenu.add(tourMenu);

        travelMenu.setText("Crea Viaggio");
        travelMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                travelMenuActionPerformed(evt);
            }
        });
        editMenu.add(travelMenu);

        menuBar.add(editMenu);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1))
                    .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(cityArrBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(cityDepBox, javax.swing.GroupLayout.PREFERRED_SIZE, 344, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(62, 62, 62)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(arriveDateField, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(DepartureDateField, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 314, Short.MAX_VALUE)
                        .addComponent(searchBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(15, 15, 15)
                        .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(userLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(111, 111, 111)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(userLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 28, Short.MAX_VALUE)
                    .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(19, 19, 19)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(searchBtn)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(cityDepBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(cityArrBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 700, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(DepartureDateField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(arriveDateField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void createPackItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createPackItemActionPerformed
        // TODO add your handling code here:
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                createFrame = new CreateFrame(status.create,null);
                createFrame.setVisible(true);
                createFrame.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        createFrame = null;
                    }
                });
            }
        });
    }//GEN-LAST:event_createPackItemActionPerformed

    private void logoutItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logoutItemActionPerformed
        // TODO add your handling code here:
        pack=null;
        userLogged=null;
        listPacketModel.clear();
        cityDepBox.setSelectedItem("");
        cityArrBox.setSelectedItem("");
        arriveDateField.setText("");
        DepartureDateField.setText("");
        userLabel.setText("");
        editMenu.setEnabled(true);
        bookingItem.setEnabled(true);
        disposeAllFrame();
        
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                dialog = new LoginDialog(guiMain, true);
                dialog.setLocationRelativeTo(guiMain);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
        
    }//GEN-LAST:event_logoutItemActionPerformed

    private void disposeAllFrame()
    {
          if(createFrame!=null)
        {
            createFrame.setVisible(false);
            createFrame.dispose();
            createFrame=null;
        }
        
        if(bookFrame!=null)
        {
            bookFrame.setVisible(false);
            bookFrame.dispose();
            bookFrame=null;
        }
        
        if(showBookFrame!=null)
        {
            showBookFrame.setVisible(false);
            showBookFrame.dispose();
            showBookFrame=null;
        }
        
        if(hotelDialog!=null)
        {
            hotelDialog.setVisible(false);
            hotelDialog.dispose();
            hotelDialog=null;
        }
        
        if(tourDialog!=null)
        {
            tourDialog.setVisible(false);
            tourDialog.dispose();
            tourDialog=null;
        }      
        
        if(travelDialog!=null)
        {
            travelDialog.setVisible(false);
            travelDialog.dispose();
            travelDialog=null;           
        }
    }
    
    
    
    private void menuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemActionPerformed
        // TODO add your handling code here:
        if(userLogged.isEmployee())
            showAllPackets();
        else
            showPacketOnsale();
    }//GEN-LAST:event_menuItemActionPerformed

    private void hotelMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hotelMenuActionPerformed
        // TODO add your handling code here:
           java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                hotelDialog = new HotelDialog(guiMain, true);
                hotelDialog.setLocationRelativeTo(guiMain);
                hotelDialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        hotelDialog=null;
                    }
                });
                hotelDialog.setVisible(true);
            }
        });
                                                 
    }//GEN-LAST:event_hotelMenuActionPerformed

    private void travelMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_travelMenuActionPerformed
        // TODO add your handling code here:
          java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                travelDialog = new TravelDialog(guiMain, true);
                travelDialog.setLocationRelativeTo(guiMain);
                travelDialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        travelDialog = null;
                    }
                });
                travelDialog.setVisible(true);
            }
        });
    }//GEN-LAST:event_travelMenuActionPerformed

    private void tourMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tourMenuActionPerformed
        // TODO add your handling code here:
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                tourDialog = new TourDialog(guiMain, true);
                tourDialog.setLocationRelativeTo(guiMain);
                tourDialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        tourDialog = null;
                    }
                });
                tourDialog.setVisible(true);
            }
        });
    }//GEN-LAST:event_tourMenuActionPerformed

    private void bookingItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bookingItemActionPerformed
        // TODO add your handling code here:
        
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                showBookFrame = new ShowBookedFrame(userLogged);
                showBookFrame.setVisible(true);
                showBookFrame.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        showBookFrame =null;
                    }
                });            
            }
            
        });
    }//GEN-LAST:event_bookingItemActionPerformed

    private void searchBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchBtnActionPerformed
        // TODO add your handling code here:
        cittaDTO arrC=null;
        cittaDTO depC=null;
        listPacketModel.clear();
        if(pack!=null)
            pack.clear();

        Date dateReturn = (Date) arriveDateField.getValue();
        Date dateDeparture = (Date) DepartureDateField.getValue();
                
        if(dateDeparture==null && dateReturn==null)
            return;
        
        int arrIndex = cityArrBox.getSelectedIndex();
        int depIndex= cityDepBox.getSelectedIndex();
        
        if(arrIndex!=0)
            arrC = (cittaDTO) cityArrBox.getSelectedItem();
        if(depIndex!=0)
            depC = (cittaDTO) cityDepBox.getSelectedItem();

        pack = tDSession.getAllPacketsWithPredicate(dateReturn, dateDeparture,arrC,depC);
        if(pack==null)
            return;
        
        int size = pack.size();
        for (int i = 0; i < size; i++)  
            listPacketModel.addElement(pack.get(i));

    }//GEN-LAST:event_searchBtnActionPerformed

    private void packetListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_packetListMouseClicked
        // TODO add your handling code here:
        JList theList = (JList) evt.getSource();

        if (bookFrame != null) {
            return;
        }

        if (evt.getClickCount() == 2)
        {
            int index = theList.locationToIndex(evt.getPoint());
            if (index >= 0)
            {
                selectedPacket = (PacchettoDTO) theList.getModel().getElementAt(index);
                if (selectedPacket == null)
                return;
            }
            if (!userLogged.isEmployee())
            {
                java.awt.EventQueue.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        bookFrame = new BookingFrame(selectedPacket);
                        bookFrame.setUser(userLogged);
                        bookFrame.setVisible(true);
                        bookFrame.addWindowListener(new java.awt.event.WindowAdapter() {
                            @Override
                            public void windowClosing(java.awt.event.WindowEvent e) {
                                bookFrame = null;
                            }
                        });
                    }
                });
            }
            else
            {
                java.awt.EventQueue.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        createFrame = new CreateFrame(status.modify,selectedPacket);
                        createFrame.setVisible(true);
                    }
                });
            }
        }
    }//GEN-LAST:event_packetListMouseClicked

    private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowGainedFocus
        // TODO add your handling code here:
        if(pack!=null)
            showAllPackets(); 
        packetList.validate();
    }//GEN-LAST:event_formWindowGainedFocus
   
    
    public void setUser(UserDTO user)
    {
        this.userLogged = user;
        userLabel.setText(user.getUsername());
        if(!user.isEmployee())
          editMenu.setEnabled(false);
        
        if(user.isEmployee())
            bookingItem.setEnabled(false);

    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TDGuiMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TDGuiMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TDGuiMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TDGuiMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() 
            {
                guiMain = new TDGuiMain();
                guiMain.setVisible(true);
            }
        });
        
        java.awt.EventQueue.invokeLater(new Runnable() {
            private LoginDialog dialog;

            @Override
            public void run() {
                dialog = new LoginDialog(guiMain, true);
                dialog.setLocationRelativeTo(guiMain);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFormattedTextField DepartureDateField;
    private javax.swing.JFormattedTextField arriveDateField;
    private javax.swing.JMenuItem bookingItem;
    private javax.swing.JComboBox cityArrBox;
    private javax.swing.JComboBox cityDepBox;
    private javax.swing.JMenuItem createPackItem;
    private javax.swing.JMenu editMenu;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JMenuItem hotelMenu;
    private javax.swing.JMenu infoMenu;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JMenuItem logoutItem;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenuItem packetItem;
    private javax.swing.JList packetList;
    private javax.swing.JMenuItem prefItem;
    private javax.swing.JButton searchBtn;
    private javax.swing.JMenuItem tourMenu;
    private javax.swing.JMenuItem travelMenu;
    private javax.swing.JLabel userLabel;
    // End of variables declaration//GEN-END:variables

    

}
